/**
 * Created by charsen on 16/6/7.
 */
directives.directive('fullScreen', ["$rootScope", "tools", "$timeout", function ($rootScope, tools, $timeout) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attr) {
            var $ele = $(element);
            scope.name = "";
            scope.type = '';
            scope.charts = [];
            scope.sheets = [];
            scope.base = $ele.width() - 40;

            // 容器的高度
            $ele.find('.content').height(document.documentElement.clientHeight * 0.7);

            // 图全屏
            $rootScope.$on('CHART_FULL_SCREEN_EV', function (e, config) {
                $ele.find('.chart-container').width(scope.base).height($ele.find('.content').height());
                $ele.modal('show');
                scope.type = 'chart';

                config.height = $ele.find('.chart-container').height() / scope.base;
                $timeout(function () {
                    scope.charts[0] = config;
                }, 0);
            });

            // 表全屏
            $rootScope.$on('SHEET_FULL_SCREEN_EV', function (e, sheet) {
                $ele.modal('show');
                scope.type = 'sheet';

                $timeout(function () {
                    scope.sheets[0] = sheet;
                    $timeout(function () {
                        $ele.find('.sheet-container').find('.sheet-wrap').height(document.documentElement.clientHeight * 0.7 - 40);
                    }, 3000);
                }, 0);
            });

            scope.close = function () {
                scope.charts.length = 0;
                scope.sheets.length = 0;
                $ele.modal('hide');
            }
        },
        templateUrl: "/trend-new-BI/app/components/common/fullScreen/fullScreenView.html"
    }
}]);